/**
 * 
 */
package model;

import javax.cim.CIMInstance;
import javax.cim.UnsignedInteger32;

/**
 * This class represent an IPTableRule on the client side
 * @author alith
 */
public class IPTableRule extends CIMObject {

    private String name;
    private String chain;
    private String source;
    private String destination;
    private String protocol;
    private String source_port;
    private String destination_port;
    private String jump;
    private UnsignedInteger32 id;
	private CIMServer server;
	
	/**
	 * Create a IPTableRule WITHOUT registering it on any server
	 * @param name the name of the IPTableRule, not stored on the server.
	 * @param chain the chain of the IPTableRule
	 * @param source the source of the IPTableRule
	 * @param destination the destination of the IPTableRule
	 * @param protocol the protocol of the IPTableRule
	 * @param source_port the source_port of the IPTableRule
	 * @param destination_port the destination_port of the IPTableRule
	 * @param jump the jump of the IPTableRule
	 * @param server the server in which the IPSecRule will eventually be stored
	 * @throws CIMBadArgument if any parameter is null or empty or not correct.
	 */
    public IPTableRule(String name,String chain, String source, String destination, String protocol, String source_port, String destination_port, String jump, CIMServer server) throws CIMBadArgument{
        this.name = name;
        this.chain = chain;
        this.source = source;
        this.destination = destination;
        this.protocol = protocol;
        this.source_port = source_port;
        this.destination_port = destination_port;
        this.jump = jump;
        this.server = server;
    }
	
    /**
     * Create an empty IPTableRule, only with the server on which it will eventually be stored.
     * @param server the server in which the IPTableRule will eventually be stored
     * @throws CIMBadArgument if any parameter is null or empty or not correct.
     */
    public IPTableRule(CIMServer server)  throws CIMBadArgument{
        this.server = server;
    }

    /**
     * Create an IPTableRule with an CIMInstance (ie a result from a request on the server)
     * @param inst the CIMInstance of the IPTableRule to create
     * @param server the server in which this new IPSecRule will eventually be stored.
     */
	public IPTableRule(CIMInstance inst,CIMServer server) {
		this.id = (UnsignedInteger32) inst.getProperty("id").getValue();
    	this.name = "regle n°"+id;//n'a aucun sens mais thomas le demande...
	    this.chain = (String) inst.getProperty("chain").getValue();
	    this.source = (String) inst.getProperty("source").getValue();
	    this.destination = (String) inst.getProperty("destination").getValue();
	    this.protocol = (String) inst.getProperty("protocol").getValue();
	    this.source_port = (String) inst.getProperty("sourcePort").getValue();
	    this.destination_port = (String) inst.getProperty("destinationPort").getValue();
	    this.jump = (String) inst.getProperty("jump").getValue();
	    this.server = server;
	}

	/* (non-Javadoc)
	 * @see model.CIMObject#delete()
	 */
	@Override
	public void delete() throws Exception {
		server.remove(this);
	}

	/* (non-Javadoc)
	 * @see model.CIMObject#modify()
	 */
	@Override
	public void modify() throws Exception {
		server.update(this);
	}

	/* (non-Javadoc)
	 * @see model.CIMObject#register()
	 */
	@Override
	public void register() throws Exception {
		server.register(this);
	}
	
	/**
	 * getter to the name of the IPSecRule
	 * @return the name of the IPSecRule
	 */
	public String getName() {
		return name;
	}

	/**
	 * setter to the name of the IPSecRule
	 * @param name the name of the IPSecRule
	 */
	public void setName(String name) {
		this.name = name;
	}
	
	/**
	 * getter to the chain of the IPSecRule
	 * @return the chain of the IPSecRule
	 */
	public String getChain() {
		return chain;
	}

	/**
	 * setter to the chain of the IPSecRule
	 * @param chain the chain of the IPSecRule
	 */
	public void setChain(String chain) {
		this.chain = chain;
	}

	/**
	 * getter to the source of the IPSecRule
	 * @return the source of the IPSecRule
	 */
	public String getSource() {
		return source;
	}

	/**
	 * setter to the source of the IPSecRule
	 * @param source the source of the IPSecRule
	 */
	public void setSource(String source) {
		this.source = source;
	}

	/**
	 * getter to the destination of the IPSecRule
	 * @return the destination of the IPSecRule
	 */
	public String getDestination() {
		return destination;
	}
	
	/**
	 * setter to the destination of the IPSecRule
	 * @param destination the destination of the IPSecRule
	 */
	public void setDestination(String destination) {
		this.destination = destination;
	}

	/**
	 * getter to the protocol of the IPSecPolicy
	 * @return the protocol of the IPSecPolicy
	 */
	public String getProtocol() {
		return protocol;
	}
	
	/**
	 * setter to the protocol of the IPSecPolicy
	 * @param protocol the protocol of the IPSecPolicy
	 */
	public void setProtocol(String protocol) {
		this.protocol = protocol;
	}
	
	/**
	 * getter to the source_port of the IPSecPolicy
	 * @return the source_port of the IPSecPolicy
	 */
	public String getSource_port() {
		return source_port;
	}
	
	/**
	 * setter to the source_port of the IPSecPolicy
	 * @param sourcePort the source_port of the IPSecPolicy
	 */
	public void setSource_port(String sourcePort) {
		source_port = sourcePort;
	}
	
	/**
	 * getter to the destination_port of the IPSecPolicy
	 * @return the destination_port of the IPSecPolicy
	 */
	public String getDestination_port() {
		return destination_port;
	}
	
	/**
	 * setter to the destination_port of the IPSecPolicy
	 * @param destinationPort the destination_port of the IPSecPolicy
	 */
	public void setDestination_port(String destinationPort) {
		destination_port = destinationPort;
	}
	
	/**
	 * getter to the jump of the IPSecPolicy
	 * @return the jump of the IPSecPolicy
	 */
	public String getJump() {
		return jump;
	}
	
	/**
	 * setter to the jump of the IPSecPolicy
	 * @param jump the jump of the IPSecPolicy
	 */
	public void setJump(String jump) {
		this.jump = jump;
	}
	
	/**
	 * getter to the id of the IPSecPolicy
	 * @return the id of the IPSecPolicy
	 */
	public int getId() {
		return id.intValue();
	}
	
	/**
	 * getter to the id of the IPSecPolicy
	 * @return the id of the IPSecPolicy
	 */
	public UnsignedInteger32 getUnsignedId() {
		return id;
	}
	
	/**
	 * setter to the id of the IPSecPolicy
	 * @param id the id of the IPSecPolicy
	 */
	public void setId(int id) {
		this.id = new UnsignedInteger32(id);
	}
	
	/* (non-Javadoc)
	 * @see object#toString()
	 */
	@Override
	public String toString() {
		return "regle:"+name+" chain:"+chain+" source:"+source+" destination:"+destination+" protocol="+protocol+" source_port="+source_port+" destination_port="+destination_port+" jump="+jump;
	}
}
